Scene = function() 
{
    this.m_movableNodes = [];
    this.m_staticNodes  = [];

    this.init = function()
    {
        for (i = 0; i < this.m_movableNodes.length; ++i)
        {
            this.m_movableNodes[i].init();
        }

        for (i = 0; i < this.m_staticNodes.length; ++i)
        {
            this.m_staticNodes[i].init();
        }
    }

    this.update = function(dt)
    {
        for (i = 0; i < this.m_movableNodes.length; ++i)
        {
            this.m_movableNodes[i].update(dt);

            //  compute a collision of movable nodes
            for (j = 0; j < this.m_movableNodes.length; ++j)
            {
                if (i != j && this.boxesIntersect(this.m_movableNodes[i], this.m_movableNodes[j]))
                {
                    this.m_movableNodes[i].collide(this.m_movableNodes[j]);
                }
            }

            //  compute a collision of static nodes
            for (k = 0; k < this.m_staticNodes.length; ++k)
            {
                if (this.boxesIntersect(this.m_movableNodes[i], this.m_staticNodes[k]))
                {
                    this.m_movableNodes[i].collide(this.m_staticNodes[k]);
                }
            }

        }
    }

    this.addNode = function(node)
    {
        if (node.isMovable())
        {
            this.m_movableNodes.push(node);
        }
        else
        {
            this.m_staticNodes.push(node);
        }
    }

    this.boxesIntersect = function(a, b)
    {
        return (Math.abs(a.m_x - b.m_x) * 2 < (a.m_width + b.m_width)) &&
               (Math.abs(a.m_y - b.m_y) * 2 < (a.m_height + b.m_height));
    }   
}
